package worker

import (
	"cron-go/internal/pkg/crontab/dao"
	"cron-go/internal/pkg/crontab/enum"
	"cron-go/internal/pkg/crontab/models"
	"time"

	"github.com/go-liam/util/conv"
)

func ClearWorker() {
	t := conv.RandomNumber(0, 9000)
	//println("func ClearWorker() run :", t)
	time.Sleep(time.Duration(t) * time.Millisecond)
	dao.FinishDaoServer.Clear()
	time.Sleep(5 * time.Second)
	dao.ReadyDaoServer.Clear()
	time.Sleep(5 * time.Second)
	dao.LogDaoServer.Clear()
	time.Sleep(5 * time.Second)
	dao.TaskDaoServer.Clear()
	time.Sleep(5 * time.Second)
	//add log
	m := new(models.TaskLogMysqlModel)
	m.TaskID = enum.ClearWorkerTaskID
	m.DoStatus = enum.DoStatusSuccess
	m.Info = enum.ClearWorkerInfo
	dao.LogDaoServer.Create(m)
}
